home *** CD-ROM | disk | FTP | other *** search
- // File "Icon LDEF.c" - System 6 and 7 Icon LDEF Routine
- // This code is placed in the public domain for free use and distribution - MJS
- //
- // 6/27/95 Changed the Hilite Mode to use accessor functions
- // Properly save and restore Handle states - MJS
- //
- // 10/16/93 First released the LDEFs to the net - MJS
- //
- // 5/23/91 Original snippet which this is shamelessly based on,
- // by Steven Falkenburg, Apple DTS
-
- // * **************************************************************************** * //
-
- #include <GestaltEqu.h>
- #include <Icons.h>
-
- // * **************************************************************************** * //
- // * **************************************************************************** * //
- // Universal Headers users can replace these with LM accessor functions
-
- pascal unsigned char GetHiliteMode(void) = { 0x1EB8, 0x0938 }; /* MOVE.B 0x0938,(A7) */
- pascal void SetHiliteMode(unsigned char) = { 0x11DF, 0x0938 }; /* MOVE.B (A7)+,0x0938 */
-
- // * **************************************************************************** * //
- // * **************************************************************************** * //
-
- pascal void main(short message, Boolean hilited, Rect *cellRect, Cell theCell,
- short dataOffset, short dataLen, ListHandle theList) {
- short iconID, hasSys7;
- long response;
- Point drawPt;
- Rect iconRect, textRect;
- RgnHandle iconRgn;
- BitMap iconMap;
- Ptr cellData;
- Handle iconHdl;
- ListPtr theListPtr;
- SignedByte hStateList, hStateCells;
- FontInfo fontInfo;
-
- if (Gestalt(gestaltSystemVersion, &response)) return;
- hasSys7 = (response >= 0x0700);
-
- // Lock down the handles
- hStateList = HGetState((Handle) theList);
- HLock((Handle) theList);
- theListPtr = *theList;
- hStateCells = HGetState((Handle) theListPtr->cells);
- HLock((Handle) theListPtr->cells);
- cellData = *(theListPtr->cells);
-
- GetFontInfo(&fontInfo);
- SetRect(&iconRect, cellRect->left + (theListPtr->cellSize.h >> 1) - 16,
- cellRect->top + ((theListPtr->cellSize.v - fontInfo.ascent) >> 1) - 16,
- cellRect->left + (theListPtr->cellSize.h >> 1) + 16,
- cellRect->top + ((theListPtr->cellSize.v - fontInfo.ascent) >> 1) + 16);
- SetPt(&drawPt, (iconRect.left + iconRect.right) >> 1,
- iconRect.bottom + fontInfo.ascent + 2);
-
- switch (message) {
- case lInitMsg:
- break;
-
- case lDrawMsg:
- EraseRect(cellRect);
- case lHiliteMsg:
-
- if (dataLen > 0) {
- if (dataLen >= 2) {
- BlockMove(cellData + dataOffset, &iconID, sizeof(iconID));
- if (iconID == 0) EraseRect(&iconRect);
- else if ((hasSys7 == 0) || PlotIconID(&iconRect, 0,
- (hilited) ? ttSelected : 0, iconID)) {
- if (iconHdl = GetResource('ICN#', iconID)) {
- HLock(iconHdl);
-
- iconMap.baseAddr = *iconHdl;
- iconMap.rowBytes = 4;
- SetRect(&iconMap.bounds,0,0,32,32);
- CopyBits(&iconMap, &theListPtr->port->portBits,
- &iconMap.bounds, &iconRect, srcCopy, 0);
-
- if (hilited) {
- iconMap.baseAddr += 128;
- CopyBits(&iconMap, &theListPtr->port->portBits,
- &iconMap.bounds, &iconRect, srcXor, 0);
- }
-
- HUnlock(iconHdl);
- ReleaseResource(iconHdl);
- }
- else EraseRect(&iconRect);
- }
- dataLen -= sizeof(iconID);
- dataOffset += sizeof(iconID);
- }
-
- // Condense if the text doesnt fit
- if (TextWidth(cellData, dataOffset, dataLen) >
- (cellRect->right - cellRect->left)) TextFace(condense);
-
- SetRect(&textRect, drawPt.h - (TextWidth(cellData, dataOffset, dataLen) >> 1) - 2,
- drawPt.v - fontInfo.ascent - 1,
- drawPt.h + (TextWidth(cellData, dataOffset, dataLen) >> 1) + 2,
- drawPt.v + 2);
-
- EraseRect(&textRect);
- MoveTo(drawPt.h - (TextWidth(cellData, dataOffset, dataLen) >> 1), drawPt.v);
- DrawText(cellData, dataOffset, dataLen);
-
- if (hilited) {
- SetHiliteMode(GetHiliteMode() ^ (1L << hiliteBit));
- InvertRect(&textRect);
- }
- }
-
- break;
-
- case lCloseMsg:
- break;
- }
-
- // Restore the Handles
- HSetState((Handle) theListPtr->cells,hStateCells);
- HSetState((Handle) theList, hStateList);
- }
-